package com.server.impl;

import com.dao.IHotBarrage;
import com.dao.IHotComment;
import com.dao.IHotList;
import com.dao.IVideoBarrage;
import com.model.DateNumber;
import com.model.HotBarrage;
import com.model.HotList;
import com.model.Sort;
import com.response.Result;
import com.server.HotBarrageService;
import com.server.HotListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

@Service
public class HotListServicelmpl implements HotListService {
    @Autowired
    private IHotList iHotList;

    @Autowired
    private IVideoBarrage iVideoBarrage;

    @Autowired
    private IHotComment iHotComment;

    @Override
    public int insertHotList (HotList hotList){return iHotList.insertHotList(hotList);}

    @Override
    public HotList getHotList(String bv){return (HotList) iHotList.getHotList(bv);}

    @Override
    public int updateHotList(HotList hotList){return iHotList.updateHotList(hotList);}

    @Override
    public int deleteHotList(String bv){return iHotList.deleteHotList(bv);}

    @Override
    public List<HotList> getAllHotList(HotList hotList){return iHotList.getAllHotList(hotList);}

    @Override
    public List<HotList> getAllAllList(HotList hotList){return iHotList.getAllAllList(hotList);}

    @Override
    public List<HotList> getAllDanceList(HotList hotList){return iHotList.getAllDanceList(hotList);}

    @Override
    public List<HotList> getAllGameList(HotList hotList){return iHotList.getAllGameList(hotList);}

    @Override
    public List<HotList> getAllDougaList(HotList hotList){return iHotList.getAllDougaList(hotList);}


    @Override
    public Result<Object> seletHotList() {
        return Result.OK(iHotList.selectList());
    }

    @Override
    public Result<Object> seletBVId(String bvid) {
        HotList hotList = new HotList();
        List<Sort> barragesorts = new ArrayList<>();
        List<Sort> commentsorts = new ArrayList<>();
        List<DateNumber> dateNumbers = new ArrayList<>();
        List<Sort> commentsorts2 = new ArrayList<>();
        List<String> commentList = new ArrayList<>();
        List<String> barrageList = new ArrayList<>();
        Map<String,Object> map = new HashMap<>(16);
        //弹幕
        hotList = iHotList.getHotList(bvid).get(0);
        barragesorts = iVideoBarrage.barrageSortFive(bvid);
        for(int i=0;i<barragesorts.size();i++){
            Pattern regex = Pattern.compile("([.,!?]+)\\1{3}");
            if(regex.equals("???")) System.out.println("yes");
            else System.out.println("no");
        }
        Calendar calendar = Calendar.getInstance();
        for (int i = 0; i < 30; i++) {
            if(i==0){
                calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 0);
            }else calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String time = df.format(calendar.getTime());
            dateNumbers.add(iVideoBarrage.videoDate(time));
        }
        barrageList = iVideoBarrage.selectBarrage(bvid);

        map.put("video",hotList);
        map.put("SortFive",barragesorts);
        map.put("videoDate",dateNumbers);
        map.put("barrageList",barrageList);

        //评论
        commentsorts = iHotComment.sexSort(bvid);
        commentsorts2 = iHotComment.commentSort(bvid);
        commentList = iHotComment.selectComment(bvid);

        map.put("sexSort",commentsorts);
        map.put("commentSort",commentsorts2);
        map.put("commentList",commentList);


        return Result.OK(map);
    }
}
